package router

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"

	"admin-nexus-backend/internal/handler"
	"admin-nexus-backend/internal/service"
)

// SetupDictRoutes 设置字典管理路由
func SetupDictRoutes(router *gin.RouterGroup, db *gorm.DB) {
	// 创建服务实例
	dictService := service.NewDictService(db)
	dictHandler := handler.NewDictHandler(dictService)

	// 字典管理路由组
	dictRoutes := router.Group("/dict")
	{
		// 字典类型
		dictRoutes.GET("/type/list", dictHandler.GetDictTypeList)
		dictRoutes.GET("/type/:id", dictHandler.GetDictTypeByID)
		dictRoutes.POST("/type", dictHandler.CreateDictType)
		dictRoutes.PUT("/type/:id", dictHandler.UpdateDictType)
		dictRoutes.DELETE("/type/:id", dictHandler.DeleteDictType)

		// 字典数据
		dictRoutes.GET("/data/list", dictHandler.GetDictDataList)
		dictRoutes.GET("/data/code", dictHandler.GetDictDataByCode) // 根据编码获取（前端下拉用）
		dictRoutes.GET("/data/:id", dictHandler.GetDictDataByID)
		dictRoutes.POST("/data", dictHandler.CreateDictData)
		dictRoutes.PUT("/data/:id", dictHandler.UpdateDictData)
		dictRoutes.DELETE("/data/:id", dictHandler.DeleteDictData)
	}
}
